#include <stdio.h>
#include <poll.h>
#include <unistd.h>
int main()
{
    struct pollfd rfds[100];
    rfds[0].fd=0;
    rfds[0].events=POLLIN;
    while(1)
    {
        int ret=poll(rfds,1,3000);
        if(ret<0)
        {
            perror("poll error");
            return 1;
        }else if(ret==0)
        {
            printf("timeout\n");
            continue;
        }else
        {
            if(rfds[0].revents&POLLIN)
            {
                char buf[1024];
                int res=read(rfds[0].fd,buf,1023);
                if(res>0)
                {
                    buf[res]=0;
                    printf("%s\n",buf);
                }
            }
        }
    }

    return 0;
}